<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>用户注册</title>
        <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
        <meta content="yes" name="apple-mobile-web-app-capable"/>
        <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
        <meta content="telephone=no" name="format-detection"/>
        <link href="../css/stylezcy.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="../js/jqueryzcy.js"></script>
        <script type="text/javascript" src="js/time.js"></script>
    </head>

    <body>
      <header  class="ui_button"></header>
        <section class="aui-flexView">
            <header class="aui-navBar aui-navBar-fixed">
                <a onclick="closeWin()" class="aui-navBar-item">
                    <i class="icon icon-return"></i>
                </a>
                <div class="aui-center">
                    <span class="aui-center-title">注册</span>
                </div>
                <a href="javascript:;" class="aui-navBar-item">
                    <i class="icon icon-news"></i>
                </a>
            </header>
            
                <div class="aui-code-box">
                   
                        <p class="aui-code-line">
                            <input type="text" class="aui-code-line-input" name="search" value="" id="username" autocomplete="off" placeholder="请输入手机号"/>
                        </p>
                        
                        <p class="aui-code-line aui-code-line-clear">
                            <input id="yzcode" type="text" class="aui-code-line-input" autocomplete="off" placeholder="短信验证码"/>
                            <input id="btn1" type="button" class="aui-btn-default" value="获取验证码" onclick="getCode()"/>
                        </p>
                        <p class="aui-code-line">
                            <input type="text" class="aui-code-line-input" name="search" value="" id="password" autocomplete="off" placeholder="请设置密码"/>
                        </p>
                        <p class="aui-code-line">
                            <input type="text" class="aui-code-line-input" name="search" value="" id="share" autocomplete="off" placeholder="邀请码（选填）"/>
                        </p>
                        <div class="aui-che-item">
                            <div class="aui-cell-che">
                                <input type="checkbox" class="aui-well-check" name="checkbox1" id="" checked="checked">
                                <i class="aui-well-icon-checked"></i>
                            </div>我已经阅读并同意 <a href="javascript:;">《喵喵视界注册协议条款》</a>
                        </div>
                        <div class="aui-code-btn">
                            <button onclick="toReg()">注册</button>
                        </div>
                    
                </div>
            
        </section>
        <script type="text/javascript" charset="utf-8">
            $(function() {

                $(".aui-code-line-input").addClear();

            });
        </script>
    </body>
    
    
    <script type="text/javascript" src="../script/api.js" ></script>
    <script type="text/javascript">
    var api_url = localStorage.getItem('api_url');
    var onoff = true;
    var code_data ;
    var user ;
    var pass ;
    apiready = function () {
      api.parseTapmode();
      var header = $api.byId('aui-header');
      $api.fixStatusBar(header);
      var headerPos = $api.offset(header);
      var body_h = $api.offset($api.dom('body')).h;

    }




    //去注册
    function toReg(){
      var username = $api.val($api.byId('username'));
      var password = $api.val($api.byId('password'));
   var yzcode = $api.val($api.byId('yzcode'));
      var share = $api.val($api.byId('share'));
      if(username == ''){
      api.toast({
          msg: '喵喵视界提醒！账号都没输入',
      });
        return;
      }
      if(password == ''){
      api.toast({
           msg: '喵喵视界提醒！密码还没输入',
      });
        return;
      }

      if(username.length < 6){
        api.toast({
             msg: ' 请输入6位数以上账号 ',
        });
        return;
      }
   if(yzcode != code_data){
      api.alert({
          title: '错误提示',
          msg: '您输入的验证码不正确',
      });
      return;
   }

api.toast({
     msg: ' 注册中 请稍等…… ',
});
      api.ajax({
          url: api_url+'login/login/create1.html',
          method: 'get',
          data: {
              values: {
                  name:username,
                  password:password,
				  share_ma:share,
				  type:'App独立注册',
				  shibie:api.deviceId,
				  imei:api.deviceId,
				  key:localStorage.getItem('anq_key'),
              }
          }
      },function(ret, err){
          if (ret) {
              if (ret.code == 0) {
                api.hideProgress();
                api.alert({
                    title: '错误~',
                    msg: ret.msg,
                });
              }else {
                //api.hideProgress();
                api.alert({
                    title: '注册成功！',
                    msg: '当前身份：体验会员',
                });
                //openLogin();
                api.ajax({
                    url: api_url+'login/login/logo.html',
                    method: 'get',
                    data: {
                        values: {
                            username: username,
                            passwd: password,
                            imei:api.deviceId,
							key:localStorage.getItem('anq_key'),
                        }
                    }
                },function(ret, err){
                    if (ret) {
						console.log( JSON.stringify( ret ) );
                        //alert( JSON.stringify( ret.msg['id'] ) );
						localStorage.setItem('accountLogin',0);
						localStorage.setItem('user_id', ret.msg['id']);
						localStorage.setItem('user_name', username);
						localStorage.setItem('password', password);
						localStorage.setItem('user_time', ret.msg['time']);
						localStorage.setItem('user_share', ret.msg['share']);
						localStorage.setItem('user_advert', ret.msg['advert']);
						localStorage.setItem('user_code', ret.msg['code']);
						localStorage.setItem('power', ret.msg['power']);
						localStorage.setItem('url', ret.msg['url']);
						localStorage.setItem('url1', ret.msg['url1']);
						localStorage.setItem('url2', ret.msg['url2']);
						localStorage.setItem('url3', ret.msg['url3']);
						localStorage.setItem('url4', ret.msg['url4']);
						localStorage.setItem('url5', ret.msg['url5']);
						localStorage.setItem('url6', ret.msg['url6']);
						localStorage.setItem('url7', ret.msg['url7']);
						localStorage.setItem('user_nickname', ret.msg['nick_name']);
						localStorage.setItem('tjryqma',ret.msg['sjyqma']);
						localStorage.setItem('stdejb',ret.msg['stjb']);
						localStorage.setItem('user_zfb',ret.msg['zfb']);
						localStorage.setItem('user_weichat', ret.msg['weichat']);
						localStorage.setItem('user_sharema',ret.msg['share_ma']);
						localStorage.setItem('user_img',ret.msg['userimg']);
                          api.sendEvent({
                            name: 'newLoingdata',
                            extra: {
                            }
                          });
						  api.closeToWin({
						     name: 'root'
						  });

                      
                    } else {
                      api.hideProgress();
                      /*   alert('网络错误！');
                            原弹窗提示*/
                            api.toast({
                                msg: '喵喵视界提醒！网络错误 请检查！'
                            });
                      //alert( JSON.stringify( err ) );
                      return;
                    }
                });


                
              }
          } else {
            api.hideProgress();
            api.alert({
                title: '糟糕~',
                msg: '网络错误！',
            });
          }
      });
    }

    //页面传参
    function openLogin(){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }


        api.openWin({
            name: 'login',
            url: './login.html',
            pageParam:{user:user,pass:pass},
        });
    }

    //获取验证码
    function getCode(){
      var yzcode = $api.val($api.byId('yzcode'));
      var btn1 = $api.byId('btn1');
      var username = $api.val($api.byId('username'));
      localStorage.setItem('reg_name',username);
      if (!onoff) {
        return;
      }
      onoff = false;

      if(username == ''){
        api.alert({
            title: '警告！',
            msg: '请输入手机号码',
        });
        onoff = true;
        return;
      }
      if(username.length != 11){
        api.alert({
            title: '警告！',
            msg: '请输入11位手机号码',
        });
        onoff = true;
        return;
      }
      code_data = RndNum(6);
      var content = escape('#code#='+code_data);
      //alert(code_data);

      api.ajax({
        url: api_url+'/login/login/fsdx',
        method: 'get'
      },function(ret, err){
      //  var url = 'http://api.978w.cn/yzmsms/index/appkey/'+ret.appkey+'/phone/'+username+'/moban/'+ret.mbid+'/app/喵喵视界/code/'+code_data;
        //alert( JSON.stringify(url) );
        //return false;
          api.ajax({
              url: 'http://v.juhe.cn/sms/send?mobile='+username+'&tpl_id='+ret.mbid+'&tpl_value='+content+'&key='+ret.appkey,
           //   url: 'http://api.978w.cn/yzmsms/index/appkey/'+ret.appkey+'/phone/'+username+'/moban/'+ret.mbid+'/app/喵喵视界/code/'+code_data,
              method: 'get'
          },function(ret, err){
                  api.toast({
                      msg: '发送成功',
                      duration: 1000,
                      location: 'middle'
                  });
                  var nuw = 60;
                  var timer = setInterval(function(){
                    nuw --;

                    if (nuw < 1) {
                    	btn1.value="获取验证码";
                //      btn1.innerHTML = '获取';
                      clearInterval(timer);
                      onoff = true;
                    }else {
                    	btn1.value=nuw+'s';
                    //  btn1.innerHTML = nuw+'s';
                    }
                  },1000)
          });

      });
      

    }

    //生成验证码
    function RndNum(n){
      var rnd="";
      for(var i=0;i<n;i++)
          rnd+=Math.floor(Math.random()*10);
      return rnd;
    }


    function closeWin(){
        api.closeWin({
        });
    }

    function openWin(name){
          var delay = 0;
          if(api.systemType != 'ios'){
              delay = 300;
          }
          api.openWin({
              name: ''+name+'',
              url: ''+name+'.html',
              bounces:false,
              delay: delay,
              slidBackEnabled:true,
              vScrollBarEnabled:false
          });
      }
</script>
    
    
    
</html>
